/*
 * sys.h
 *
 *  Created on: 2018年5月6日
 *      Author: 0yfj0
 */

#ifndef SYS_H_
#define SYS_H_

#ifdef __cplusplus
extern "C"
{
#endif  /* __cplusplus */
#include <stdint.h>
#include "sys_conf.h"

/*----------------------------------------------------------------------------*/
#define SYS_DAY_SEC_MAX		( 86400 )
typedef struct
{
	char dev_name[16];
	uint32_t passwd;
} sys_conf_t;

typedef struct
{
	uint32_t poweron;/* 开机次数 */
	uint32_t total_run;/* 累计运行时间 */
	uint32_t run;/* 当前运行时间 */
	uint32_t sec;/* 当前时间 */
	uint32_t t100ms;
	uint32_t t10s;

	sys_conf_t conf;
	char pubkey[16];/* 公私 */
	uint32_t dsec;/* 从00:00点开始计数当前秒数 */
	uint32_t deny :4;/* 拒绝连接 */
	uint32_t disconn :4;/* 延迟断开连接 */
	struct
	{
		uint32_t auth;/* 连接认证标记 */
		uint32_t magic;
	} flag;
} sys_t;
extern sys_t sys;

/*----------------------------------------------------------------------------*/
#include "sys_mem.h"
#define sys_malloc		mem_malloc
#define sys_calloc		mem_calloc
#define sys_realloc		mem_realloc
#define sys_free		mem_free

void sys_error_handle(void);

uint16_t sys_var_write(int var, uint32_t off, void *buff, uint16_t len);
uint16_t sys_var_read(int var, uint32_t off, void *buff, uint16_t len);

int sys_conf_read(uint16_t off, void *buff, uint16_t len);
int sys_conf_write(uint16_t off, void *buff, uint16_t len);

int sys_flash_erase(int sector);
int sys_flash_write(int sector, int off, void *buf, uint16_t len);
int sys_flash_read(int sector, int off, void *buf, uint16_t len);

/*----------------------------------------------------------------------------*/
#include "sys_error.h"

/*----------------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif  /* __cplusplus */
#endif /* SYS_H_ */
